<?php


namespace app\admin\validate\setting;

use tmcore\base\BaseValidate;

/**
 * 消息管理验证器
 */
class NoticeValidate extends BaseValidate
{
    protected $rule = [
        'id' => 'require',
        'scene' => 'require',
        'name' => 'require',
        'type' => 'require',
        'status' => 'require',
        'identify' => 'require|checkIdentify',
    ];

    protected $message = [
        'id.require' => 'id不能为空',
        'scene.require' => '场景编码不能为空',
        'name.require' => '场景名称不能为空',
        'type.require' => '场景类型不能为空',
        'status.require' => '状态不能为空',
        'identify.require' => '消息渠道参数不能为空',
    ];

    /**
     * 添加消息场景
     * @return NoticeValidate
     */
    public function sceneAdd()
    {
        return $this->only(['scene','name','type','status']);
    }

    /**
     * 编辑消息场景
     * @return NoticeValidate
     */
    public function sceneEdit()
    {
        return $this->only(['id','identify','status']);
    }


    /**
     * 获取配置参数信息场景
     * @return NoticeValidate
     */
    public function sceneDetail()
    {
        return $this->only(['id']);
    }


    /**
     * 切换开关场景
     * @return NoticeValidate
     */
    public function sceneChange()
    {
        return $this->only(['id','identify','status']);
    }

    /**
     * 检查消息渠道标识
     * @param $value
     * @return bool|string
     */
    public function checkIdentify($value)
    {
        if(!in_array($value, ['system','sms','mail','wechat','applet'])) return '消息渠道标识参数错误';
        return true;
    }
}